package com.isesol.ime.dal.mapper;

import com.isesol.arch.common.dal.*;
import com.isesol.ime.dal.model.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.*;

import java.util.*;

/**
 * 订阅反馈
 *
 * @author peter zhang
 */
@Repository
public interface SubscriptionFeedbackMapper extends GenericMapper<SubscriptionFeedbackDO> {

	List<SubscriptionFeedbackDO> findAll(String machineId);

	SubscriptionFeedbackDO findBySubId(@Param("subId") long subId);

	Long findOneByMachineIdAndRuleName(@Param("machineId") String machineId,
	                                   @Param("ruleName") String ruleName);

	@Update("update ime.sub_feedback set feedback=0 where machine_id=#{machineId} and status='1' and rule_name=#{ruleName}")
	void updateFeedbackStatusByMachineIdAndRuleName(@Param("machineId") String machineId,@Param("ruleName")String ruleName);

	@Select("select count(*) from ime.sub_feedback where machine_id=#{machineId} and status='1' and feedback='0'")
	Long unFeedbackCount(@Param("machineId") String machineId);

	@Select("select sub_id from ime.sub_feedback where machine_id=#{machineId} and status='1' and feedback='0' limit 1")
	Long findUnFeedbackSubIdByRuleTye(@Param("machineId") String machineId,
	                                  @Param("ruleType") String ruleType);

	void delBySubId(@Param("subId") long subId);

}
